<template>
  <div class="list">
    <div class="content-head" style="margin-bottom: 20px;">
      <div class="sort-keys">
      

        <span style="margin-left: 20px; margin-right: 6px;">日期:</span>
        <iDatePicker :showTime="false" style="margin-left: 10px;" placeholder="不选则不限制" v-model="filter.min_day"></iDatePicker>
        至
        <iDatePicker :showTime="false" style="margin-left: 0px;" placeholder="不选则不限制" v-model="filter.max_day"></iDatePicker>


      </div>
    </div>
    <a-table class="table" :rowKey="row => row.uuid" :dataSource="list" :pagination="pagination" :size="size">
      <a-table-column title="用户" width="120px">
        <template slot-scope="row">
          <div class="user" v-if="row.user">
            <img :src="row.user.headimg" alt="用户头像">
            <div>
              <div>{{ row.user.name }}</div>
              <div>{{row.user.phone}}</div>
            </div>
            <a-tag color="red" style="margin-left:10px;" v-if="row.user.status === 2">已拉黑</a-tag>
                <a-tag color="red" style="margin-left:10px;" v-if="row.user.is_rb === 1">马甲</a-tag>
                <a-tag color="red" style="margin-left:10px;" v-if="row.user.is_rb2 === 1">主播</a-tag>
                <a-tag color="red" style="margin-left:10px;" v-if="row.user.is_liu === 1">老六</a-tag>
                <a-tag color="red" style="margin-left:10px;" v-if="row.user.is_nopay === 1">禁付</a-tag>
                <a-tag color="blue" style="margin-left:10px;" v-if="row.user.click_id">微广</a-tag>
          </div>
        </template>
      </a-table-column>
      <a-table-column title="微信群" width="80px" >
        <template slot-scope="row">
          <a-tag style="margin-left:10px;" v-for="(item, index) in row.qy_groups">{{item}}</a-tag>
        </template>
      </a-table-column>
      <a-table-column title="提现" width="100px">
        <template slot-scope="row">
          <div>日提现: {{$tool.formatPrice(row.drtx)}}</div>
          <div>总提现: {{$tool.formatPrice(row.ztx)}}</div>
        </template>
      </a-table-column>
      <a-table-column title="支付" width="100px">
        <template slot-scope="row">
          <div v-if="row.drsy > 0" style="color:red">日支付: {{$tool.formatPrice(row.drzf)}}</div>
          <div v-else>日支付: {{$tool.formatPrice(row.drzf)}}</div>
          <div v-if="row.zsy > 0" style="color:red">总支付: {{$tool.formatPrice(row.zzf)}}</div>
          <div v-else>总支付: {{$tool.formatPrice(row.zzf)}}</div>
        </template>
      </a-table-column>
      <a-table-column title="提货" width="100px">
        <template slot-scope="row">
          <div>日提货: {{$tool.formatPrice(row.drth)}}</div>
          <div>总提货: {{$tool.formatPrice(row.zth)}}</div>
        </template>
      </a-table-column>
      <a-table-column
        title="货币"
        width="80px"
      >
        <template slot-scope="row">
          <div v-if="row.user">红包: {{row.user.redpack / 100}}元</div>
          <div v-if="row.user">积分: {{row.user.score}}</div>
        </template>
      </a-table-column>

      <a-table-column title="已结算佣金" width="80px" >
        <template slot-scope="row">
          <a href="javascript:;" v-if="row.user" @click="handleRecordLog(row.user.id)">{{row.user.completed_money_brokerage / 100}}</a>
        </template>
      </a-table-column>

      <a-table-column title="操作明细" width="80px" >
        <template slot-scope="row">
          <a href="javascript:;" v-if="row.user" @click="handleMxLog(row.user.id)">操作明细</a>
        </template>
      </a-table-column>

      <a-table-column title="收益明细" width="80px" >
        <template slot-scope="row">
          <a href="javascript:;" v-if="row.user" @click="handleSyLog(row.user.id)">收益明细</a>
        </template>
      </a-table-column>
      

    </a-table>
    <a-modal title="用户明细(默认显示30天内的)" style="top: 100px;" :visible="isMxLog" width="1200px" @cancel="isMxLog = false" :footer="null">
      <Mxlog v-if="isMxLog" :user_id="user_id" @cancel="isMxLog = false"></Mxlog>
    </a-modal>

    <a-modal title="收益明细(默认显示30天内的)" style="top: 100px;" :visible="isSyLog" width="1200px" @cancel="isSyLog = false" :footer="null">
      <Sylog v-if="isSyLog" :user_id="user_id" @cancel="isSyLog = false"></Sylog>
    </a-modal>

    <a-modal title="佣金记录" style="top: 100px;" :visible="isRecordLog" width="1200px" @cancel="isRecordLog = false" :footer="null">
       <Recordlog v-if="isRecordLog" :user_id="user_id" :logtype="logtype" @cancel="isRecordLog = false" @success="fetchData"></Recordlog>
    </a-modal>
  </div>
</template>
<script>
  import moment from 'moment'
  import ISwitch from '@/components/ISwitch/ISwitch'

  import IDatePicker from "@/components/IDatePicker/IDatePicker.vue"
  import Mxlog from "/src/views/userList/components/Mxlog.vue"
  import Sylog from "/src/views/userList/components/Sylog.vue"
  import Recordlog from "/src/views/agent/components/Recordlog.vue"

  const resourceType = 'daywithdraw'
  const resourceTypeText = '每日提现'

  export default {
    components: {
      ISwitch,
      IDatePicker,
      Mxlog,
      Sylog,
      Recordlog
    },
    props: {
      params: {
        type: Object
      },
    },
    data() {
      return {
        resourceTypeText,
        list: [],
        isMxLog: false,
        isSyLog: false,
        isRecordLog: false,
        user_id: 0,
        page: 1,
        per_page: 10,
        total: 0,
        filter: {
          min_day: '',
          max_day: ''
        }
      }
    },
    watch: {
      params() {
        this.refreshData()
      },
      'filter.min_day'() {
        if(this.filter.min_day && this.filter.max_day){
          this.refreshData()
        }else if(!this.filter.min_day && !this.filter.max_day){
          this.refreshData()
        }
      },
      'filter.max_day'() {
        if(this.filter.min_day && this.filter.max_day){
          this.refreshData()
        }else if(!this.filter.min_day && !this.filter.max_day){
          this.refreshData()
        }
      }
    },
    computed: {
      
    },
    created() {
      this.fetchData()
    },
    methods: {
      handleRecordLog(user_id){
        this.isRecordLog = true;
        this.user_id = user_id;
      },
      handleMxLog(user_id){
        this.isMxLog = true;
        this.user_id = user_id;
      },
      handleSyLog(user_id){
        this.isSyLog = true;
        this.user_id = user_id;
      },
      refreshData() {
        this.page = 1
        this.fetchData()
      },
      fetchData() {
        this.isEdit = false
        this.$http.get(`/${resourceType}`, {
          params: {
            ...this.params,
            page: this.page,
            per_page: this.per_page,
            min_day: this.filter.min_day,
            max_day: this.filter.max_day
          }
        }).then(res => {
          this.list = res.data.list
          this.total = res.data.item_total
        }).finally(() => {
          this.loading = false
        })

      },
    }
  }
</script>
<style lang="scss" scoped>
  .value-font {
    font-weight: 500;
    font-size: 110%;
  }
  .content-head {
    display: flex;
    justify-content: space-between;
    flex-wrap: wrap;
  }

  .sort-keys {
    display: flex;
    align-items: center;

    .tab-list {
      display: flex;
      margin-top: 6px;
      border-bottom: 1px solid #e1e1e1;
      margin-right: 50px;

      .item {
        margin-right: 30px;
        padding: 0px 10px 4px 10px;
        cursor: pointer;
        font-weight: 500;

        &.actived {
          color: #1890FF;
          border-bottom: 3px solid #1890FF;
        }

        &:hover {
          color: #1890FF;
        }
      }
    }

  }

  .table {
    .thumb {
      height: 60px;
      border-radius: 6px;
    }

    .content-image {
      height: 60px;
      width: 60px;
      margin-right: 10px;
      margin-bottom: 10px;
      object-fit: cover;
      border-radius: 10px;
      cursor: pointer;

      &:hover {
        opacity: 0.8;
      }
    }

    .user {
      display: flex;
      // flex-wrap: wrap;
      align-items: center;
      img {
        width: 26px;
        height: 26px;
        margin-right: 6px;
        border-radius: 50%;
        overflow: hidden;
      }
      .gender-man, .gender-woman {
        margin-left: 5px;
        font-size: 12px;
      }
      .gender-man {
        color: #409EFF;
      }
      .gender-woman {
        color: #F56C6C;
      }
    }
  }
</style>
